home *** CD-ROM | disk | other *** search
/ SGI Hot Mix 8 / Hot Mix 8.iso / .all / demos / Imagicians / InstallIt2 (.txt) < prev    next >
Text File  |  1994-06-22  |  11KB  |  363 lines

  1. #!/bin/csh -f
  2. #
  3. #       MYAPP = name of the application executable
  4. #       INST_DIR = name of the installation directory that will be created
  5. #                  (this is the directory name, not the full path name)
  6. #       CD_PATH = directory path of the location of the software
  7. #                 on the HotMix CD-ROM (it must begin with "$HOTMIXDIR",
  8. #                 which is the mount point for the CD-ROM drive).
  9. #       KBYTES_REQ = required size of the full installation (in Kbytes).
  10. #
  11. #   You will also need to change the MYAPP, INST_DIR, and CD_PATH
  12. #   parameters in the InstallIt, RemoveIt, and RemoveIt2 scripts.
  13. #
  14. #   In this simple example, the installation just involves copying
  15. #   the software to the hard disk, and then launching the application.
  16. #
  17. #   For the given parameters in this example, if there is enough space
  18. #   in /usr, the entire $HOTMIXDIR/demos/Digital_Media/SGI directory
  19. #   will be copied into a directory named /usr/tmp/SGI.  If the user
  20. #   specifies a different installation directory, the full pathname
  21. #   of the base directory is read.  So, if the user enters /disk2/tmp,
  22. #   the entire $HOTMIXDIR/demos/Digital_Media/SGI will be copied
  23. #   into a directory named /disk2/tmp/SGI.  In this case, the application
  24. #   is then launched by executing /disk2/tmp/SGI/showcase.
  25. #
  26. #   In your situation, the installation will probably be more complicated,
  27. #   so you'll need to change the code at the end of the script, as well
  28. #   (ie., change the code following the "---------").
  29. #
  30. #   The rest of the script should not require modification.
  31. #
  32. #   All of the InstallIt and RemoveIt scripts should reside in the
  33. #   $CD_PATH directory.
  34. #
  35. #                                                 Marvin Kong
  36. #                                                 Silicon Graphics, Inc.
  37. #                                                 4/9/93
  38.  
  39. set MYAPP=Chances_Art.csh
  40. set INST_DIR=Imagicians
  41. set CD_PATH=$HOTMIXDIR/demos/Imagicians
  42. set KBYTES_REQ=20050
  43.  
  44. #
  45. #  Test to see if on the new Indy filesystem or old one.
  46. #
  47.  
  48. set TEST_NEW=`df -k /usr | /usr/bin/awk '{print $7}'`
  49.  
  50. if ( "$TEST_NEW" == "Mounted /" ) then
  51.    set FILE_STRUCTURE=new
  52. else
  53.    set FILE_STRUCTURE=old
  54. endif
  55.  
  56. #
  57. #  Determine the INST_PATH name.
  58. #
  59. #  First try /usr/tmp;  then if necessary, ask for another directory.
  60. #
  61.     
  62. if ( $KBYTES_REQ < 1000 ) then
  63.     set MBYTES_REQ=1
  64. else
  65.     @ MBYTES_REQ = ($KBYTES_REQ) / 1000
  66. endif
  67.  
  68. if ( $FILE_STRUCTURE == "new" ) then
  69.    set KBYTES_AVAIL=`df -k / | /bin/grep / | /usr/bin/awk '{print $5}'`
  70. else
  71.    set KBYTES_AVAIL=`df -k /usr | /bin/grep /usr | /usr/bin/awk '{print $5}'`
  72. endif
  73.  
  74. if ( -w /usr/tmp ) then
  75.  
  76.     if ( $KBYTES_AVAIL > $KBYTES_REQ ) then
  77.  
  78.         set INST_PATH=/usr/tmp/$INST_DIR
  79.  
  80.         echo " "
  81.         echo "This demo requires $MBYTES_REQ Mbytes of disk space."
  82.         echo " "
  83.         echo "It will be installed in a directory named $INST_PATH"
  84.         echo "Is this OK (y/n)?  \c"
  85.         set ans=($<)
  86.         if ( $ans != 'y' ) then
  87.             echo " "
  88.             echo "Do you want to install in another directory (y/n)?  \c"
  89.             set ans2=($<)
  90.             if ( $ans2 != 'y' ) then
  91.                 echo " "
  92.                 echo "... Bye."
  93.                 sleep 3
  94.                 exit
  95.             else
  96.                 set INST_PATH=none
  97.             endif
  98.         else
  99.             if ( -d $INST_PATH ) then
  100.                 echo " "
  101.                 echo "It seems the demo is already installed.  Continue anyway (y/n)?  \c"
  102.                 set ans3=($<)
  103.                 if ( $ans3 != 'y' ) then
  104.                     echo " "
  105.                     echo "... Bye."
  106.                     sleep 3
  107.                     exit
  108.                 endif
  109.                 rm -rf $INST_PATH
  110.             endif
  111.         endif
  112.     else
  113.         set INST_PATH=none
  114.     endif
  115. else
  116.     set INST_PATH=none
  117. endif
  118.  
  119. if ( $INST_PATH == "none" ) then
  120.  
  121. #   Read name of installation directory.
  122.  
  123.     echo " "
  124.     echo "This demo requires $MBYTES_REQ Mbytes of disk space."
  125.  
  126.     LOOP1:
  127.  
  128.     unset INSTDIR_FILESYS
  129.  
  130.     echo " "
  131.     echo "Enter the full path name of an existing directory"
  132.     echo "in which to copy the software (or enter 'q' to quit):  \c"
  133.     set ans=($<)
  134.  
  135. #   Check validity of the path name.  If it contains only a "/",
  136. #   this will cause a divide by zero, and fail.
  137.     set TEST1=`echo $ans | cut -f2 -d"/"`
  138.     if ( ! $#TEST1 ) then
  139.             echo " "
  140.             echo "You cannot use directory /.  Please try again."
  141.             goto LOOP1
  142.     endif
  143.  
  144.     if ( $ans == 'q' ) then
  145.         echo " "
  146.         echo "... Bye."
  147.         sleep 3
  148.         exit
  149.     else if ( $#ans == 0 ) then
  150.         echo " "
  151.         echo "Input error.  Please try again."
  152.         goto LOOP1
  153.     else
  154.  
  155. #       Check validity of the path name again.  It must begin with "/".
  156.         set TEST2=`echo $ans | cut -f1 -d"/" -s`
  157.         set TEST3=`echo $ans | cut -f2 -d"/" -s`
  158.         if ( ( $#TEST2 ) || ( ! $#TEST3 ) ) then
  159.                 echo " "
  160.                 echo "The pathname must begin with /.  Please try again."
  161.                 goto LOOP1
  162.         endif
  163.  
  164.         if ( -d $ans ) then
  165.  
  166.             echo " "
  167.             echo "A $INST_DIR directory will be created in $ans."
  168.             echo "Is this OK (y/n)?:  \c"
  169.             set ans2=($<)
  170.             if ( $ans2 != 'y' ) goto LOOP1
  171.  
  172. #           Determine the space available for the filesystem
  173. #           containing the requested directory.
  174. #
  175.  
  176. #            Check to see if the directory is actually a link or an
  177. #            nfs mount and do appropriate checks.
  178.  
  179.             if ( -l $ans ) then 
  180.                 cd $ans
  181.                 set CDIR=`pwd`
  182.                 set KBYTES_AVAIL=`df -k $CDIR | /usr/bin/awk '{print $5}'`
  183.             endif
  184.  
  185.             touch $ans/hmtest
  186.             if ( ! -r $ans/hmtest ) then
  187.  
  188.                 echo "Can not write to $ans, please choose another directory."
  189.                 goto LOOP1
  190.             endif
  191.             /bin/rm -f $ans/hmtest
  192.  
  193.                 
  194. #           First, find all the mounted filesystems.
  195.             set FILESYSTEMS=`df -k | awk '{print $7}' | grep /`
  196.  
  197. #           Now, beginning with the full path name of the
  198. #           requested directory, start stripping off the trailing
  199. #           subdirectory names, and compare this to the existing
  200. #           file system names.  If these match exactly, then we've
  201. #           found the right file system.
  202.  
  203.             set TEST4=`echo $ans | cut -f3 -d"/"`
  204.             if ( ! $#TEST4 ) then
  205.                 set PATH=$ans
  206.             else
  207.                 set PATH=`dirname $ans`
  208.             endif
  209.             LOOP2:
  210.                 foreach FILESYSTEM ($FILESYSTEMS)
  211.  
  212. #                   Don't do the test if $FILESYSTEM == "/"
  213.                     set TEST5=`echo $FILESYSTEM | cut -f2 -d"/"`
  214.                     if ( $#TEST5 != 0 ) then
  215.  
  216.                         if ( $PATH == $FILESYSTEM ) then
  217.                             set INSTDIR_FILESYS=$PATH
  218.                         endif
  219.                     endif
  220.                 end
  221.                 set PATH=`dirname $PATH`
  222.  
  223. #           Continue looping until we've stripped the pathname
  224. #           down to only "/", or until we find the file system.
  225.  
  226.             set LOOPTEST=`echo $PATH | cut -f2 -d"/"`
  227.             if (( $#LOOPTEST != 0 ) && ( ! $?INSTDIR_FILESYS )) goto LOOP2
  228.  
  229.             if ( $?INSTDIR_FILESYS ) then
  230.  
  231. #               Determine the available space
  232.  
  233.                 set KBYTES_AVAIL=`df -k $INSTDIR_FILESYS | /bin/grep $INSTDIR_FILESYS | /usr/bin/awk '{print $5}'`
  234.  
  235.             else
  236.                 if ( $FILE_STRUCTURE == "new" ) then
  237.                   set KBYTES_AVAIL=`df -k / | /bin/grep / | /usr/bin/awk '{print $5}'`
  238.                 else
  239.                 echo " "
  240.                 echo "  ERROR:  Can't determine the amount of available disk"
  241.                 echo "          space for the directory you requested."
  242.                 echo " "
  243.                 echo "          Continue anyway (y/n)?  \c"
  244.                 set ans3=($<)
  245.                 if ( $ans3 == 'y' ) then
  246.                     @ KBYTES_AVAIL = ($KBYTES_REQ) + 1
  247.                 else
  248.                     echo " "
  249.                     echo "... Bye."
  250.                     sleep 3
  251.                     exit
  252.                 endif
  253.             endif
  254.        endif
  255.  
  256.             if ( $KBYTES_AVAIL > $KBYTES_REQ ) then
  257.                 if ( -w $ans ) then
  258.  
  259. #                   Success!!!
  260.  
  261.                     set INST_PATH=$ans/$INST_DIR
  262.                     echo " "
  263.                 else
  264.                     echo " "
  265.                     echo "Can't write to directory $ans."
  266.                     echo "Please try again."
  267.                     goto LOOP1
  268.                 endif
  269.             else
  270.                 echo " "
  271.                 echo "Not enough disk space available."
  272.                 echo " "
  273.                 echo "     Required space = $KBYTES_REQ Kbytes"
  274.                 echo "    Available space = $KBYTES_AVAIL Kbytes"
  275.                 echo " "
  276.                 echo "Please try again."
  277.                 goto LOOP1
  278.             endif
  279.         else
  280.             echo " "
  281.             echo "Can't find directory $ans."
  282.             goto LOOP1
  283.         endif
  284.     endif
  285.  
  286.     # Check installation directory.
  287.     if ( -d $INST_PATH ) then
  288.         echo " "
  289.         echo "It seems the demo is already installed.  Continue anyway (y/n)?  \c"
  290.         set ans3=($<)
  291.         if ( $ans3 != 'y' ) then
  292.             echo " "
  293.             echo "... Bye."
  294.             sleep 3
  295.             exit
  296.         endif
  297.  
  298.         rm -rf $INST_PATH
  299.     endif
  300. endif
  301.  
  302. #  Store INST_PATH in a file so it can be communicated to the RemoveIt script.
  303. #
  304. #  First, try to put it in /usr/tmp.  If we can't, then put it in /tmp
  305. #  and in the user's home directory.  If put in /tmp, the file will
  306. #  disappear if the machine is rebooted.  If put in the user's home
  307. #  directory, we won't be able to find it if the user trying to remove
  308. #  the software is not the same as the user who installed it.  Either
  309. #  case isn't very good, but it's the best we can do if we can't write
  310. #  to /usr/tmp.
  311.  
  312. /bin/rm -f /usr/tmp/HOTMIXPATH_$INST_DIR > /dev/null
  313. /bin/rm -f /tmp/HOTMIXPATH_$INST_DIR > /dev/null
  314. /bin/rm -f ~/HOTMIXPATH_$INST_DIR > /dev/null
  315.  
  316. if ( -w /usr/tmp ) then
  317.     echo "setenv INST_PATH $INST_PATH" > /usr/tmp/HOTMIXPATH_$INST_DIR
  318.     /bin/chmod 666 /usr/tmp/HOTMIXPATH_$INST_DIR
  319. else
  320.     echo "setenv INST_PATH $INST_PATH" > /tmp/HOTMIXPATH_$INST_DIR
  321.     /bin/chmod 666 /tmp/HOTMIXPATH_$INST_DIR
  322.  
  323.     echo "setenv INST_PATH $INST_PATH" > ~/HOTMIXPATH_$INST_DIR
  324.     /bin/chmod 666 ~/HOTMIXPATH_$INST_DIR
  325. endif
  326.  
  327. #
  328. #-----------------------------------------------------------------------
  329. #
  330. #  Now that we've finally determined INST_PATH, do the installation.
  331. #  In this case, just copy the software and execute the application.
  332.  
  333. echo " "
  334. echo "Installing Chances_Art.  Please wait..."
  335. /bin/cp -r $CD_PATH $INST_PATH
  336.  
  337. echo " "
  338. echo "Done."
  339.  
  340. echo " "
  341. echo "To run the demo, move to the $INST_PATH directory"
  342. echo "and execute Chances_Art."
  343. echo " "
  344. echo " "
  345. echo "Do you want to run the demo now (y/n)?  \c"
  346. set ans=($<)
  347. if ( $ans == 'y' ) then
  348.  
  349.     cd $INST_PATH
  350.  
  351.     ./$MYAPP
  352.  
  353. #   If your application is compiled so as to run in the background,
  354. #   you must execute it via the "wait.csh" script, as shown below
  355. #   (see the wait.csh script for more info).
  356. #   ./wait.csh ./$MYAPP
  357.  
  358. else
  359.     echo "... Bye."
  360.     sleep 3
  361. endif
  362.  
  363.